<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        // 正则的创建如果需要使用变量，就必须使用new进行实例化创建
        //    new RegExp(str , 'ig')


        let reg = /good/ig ;

        let reg2 = new RegExp('good' , 'ig') ;

        let str = '^good$' ;

        // let reg3 = /str/   // 判断str这个字符串   而不是会识别变量

        let reg3 = new RegExp(str , 'i') ;
        console.log(reg3);

        console.log(reg3.test('Good'));

    </script>
    
</body>
</html>